home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////// //
- // $Id: RegInfo.cxx,v 1.1 1994/02/18 19:49:58 bmott Exp $
- /////////////////////////////////////////////////////////////////////////////// //
- // RegInfo.cxx
- //
- // This class is used by BasicCPU (and derived classes) to manage a list of
- // of register structures.
- //
- //
- // BSVC "A Microprocessor Simulation Framework"
- // Copyright (c) 1993
- // By: Bradford W. Mott
- // October 25,1993
- //
- ///////////////////////////////////////////////////////////////////////////////
- // $Log: RegInfo.cxx,v $
- // Revision 1.1 1994/02/18 19:49:58 bmott
- // Initial revision
- //
- ///////////////////////////////////////////////////////////////////////////////
-
- #include <string.h>
- #include "RegInfo.hxx"
-
- ///////////////////////////////////////////////////////////////////////////////
- // One of the RegisterInformation constructor
- ///////////////////////////////////////////////////////////////////////////////
- RegisterInformation::RegisterInformation(const char* n,const char* v,
- const char *d)
- {
- name=new char[strlen(n)+1];
- hex_value=new char[strlen(v)+1];
- description=new char[strlen(d)+1];
-
- strcpy(name,n);
- strcpy(hex_value,v);
- strcpy(description,d);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // The other RegisterInformation constructor
- ///////////////////////////////////////////////////////////////////////////////
- RegisterInformation::RegisterInformation()
- {
- name=(char*)0;
- hex_value=(char*)0;
- description=(char*)0;
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // The RegisterInformation destructor
- ///////////////////////////////////////////////////////////////////////////////
- RegisterInformation::~RegisterInformation()
- {
- delete[] name;
- delete[] hex_value;
- delete[] description;
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Set the name, hex_value, and description of the register
- ///////////////////////////////////////////////////////////////////////////////
- void RegisterInformation::Set(const char* n,const char* v,const char *d)
- {
- delete[] name;
- delete[] hex_value;
- delete[] description;
-
- name=new char[strlen(n)+1];
- hex_value=new char[strlen(v)+1];
- description=new char[strlen(d)+1];
-
- strcpy(name,n);
- strcpy(hex_value,v);
- strcpy(description,d);
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////
- // The RegisterInformationList constructor
- ///////////////////////////////////////////////////////////////////////////////
- RegisterInformationList::RegisterInformationList(BasicCPU* cpu)
- {
- head=tail=(void*)0;
- number_of_elements=0;
- cpu->BuildRegisterInformationList(this);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // The class destructor
- ///////////////////////////////////////////////////////////////////////////////
- RegisterInformationList::~RegisterInformationList()
- {
- RegisterInformationNode* p;
- RegisterInformationNode* q;
-
- // Delete the list of nodes
- p=head;
- while(p!=(void*)0)
- {
- q=p->next;
- delete p;
- p=q;
- }
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Append a new node to the list
- ///////////////////////////////////////////////////////////////////////////////
- void RegisterInformationList::Append(const char* name,
- const char* hex_value,
- const char* description)
- {
- RegisterInformationNode* n;
- n = new RegisterInformationNode(name,hex_value,description);
-
- if(tail==(void*)0)
- {
- head = tail = n;
- }
- else
- {
- tail->next = n;
- tail = n;
- }
-
- ++number_of_elements;
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Return a specific element from the list
- ///////////////////////////////////////////////////////////////////////////////
- int RegisterInformationList::Element(int index,RegisterInformation& info)
- {
- RegisterInformationNode* p;
- int t;
-
- for(t=0,p=head;(t<index) && (p!=(void*)0);++t,p=p->next);
-
- if (t==index)
- {
- info.Set(p->Name(),p->HexValue(),p->Description());
- return(1);
- }
- else
- {
- return(0);
- }
- }
-
-